#ifndef _DB_API__H_
#define _DB_API__H_

#include "ff.h"
#include "db_mp3_parse.h"
#include "db_flac_parse.h"
#include "db_wma_parse.h"
#include "db_ogg_parse.h"
#include "db_ape_parse.h"
#include "db_format.h"
#include "db_api.h"
#include "db_util.h"
#include "db_audio.h"
#include "db_album.h"
#include "db_artist.h"
#include "db_video.h"
#include "db_image.h"
#include "db_ebook.h"
#include "db_wave.h"
#include "db_folder.h"
#include "db_like.h"
#include "db_tag.h"

#define CB	hDB->cb(__LINE__, (int)__FILE__);
#define DB_SLP OAL_sleep(1);

extern int sprintf(char* const _Buffer, char const* const _Format, ...);
extern int xprintf(char const* const _Format, ...);

typedef struct tag_DBContent
{
	int version;				//版本号；格式 == 高16位 + 低16位 == “Hi . Lo” 
	int dirty;					//1==数据库脏，需要重新扫描
	
	unsigned int ebookSN;		//ebook流水号

	unsigned int sector_size;
	unsigned int sd_free_clst;	//SD卡剩余空间

	unsigned int audio_count;
	unsigned int album_count;
	unsigned int artist_count;

	unsigned int video_count;
	unsigned int image_count;
	unsigned int ebook_count;
	unsigned int wave_count;
	unsigned int like_count[MAXLIKETYPE];
	unsigned int tag_count;

	int mount;					//mount标记，1==mounted
	int percent;				//驱动进度条
	db_cb cb;
	get_sd_status cb_get_sd_status;
	OAL_MUTEX mutex;

	FIL fdb;
}DBCONTENT;

#if SORT == 1
typedef struct tag_SortNode
{
	unsigned long long id[2];
	int offset;
}
SORTNODE;
void _db_sort(SORTNODE * tmp, int rec_cnt);
#endif

#define CONTENTSIZE ((int)(&(((DBCONTENT*)(0))->mount)))
extern DBCONTENT * hDB;

int save_content();
int load_content();
int _db_init(db_cb cb, get_sd_status cb_get_sd_status);
void _db_free(void);
int _db_mount(void);
int _db_unmount(void);
int _db_reset(void);

#endif
